<template>
	<view>
		<view class="body" style=" max-width:640px; overflow:auto; overflow-x:hidden">
			<dfHeader></dfHeader>
			<div class='content1 grey'>
				<section class="index_st7 clearfix mt10">
					<div class="index_st7_ct1">{{search_str}}</div>
					<div class="index_st7_ct4">
						<div class="line"></div>
					</div>
				</section>
				<section class="index_st12 clearfix ">
					<div class="index_st12_all mt10" v-for="(data,i) in dataList" @tap="goDetail(data)">
						<div class="index_st12_ct1"><img :src="data.pic" /></div>
						<div class="index_st12_ct2">
							<div class="new_title">{{data.title}}</div>
							<div class="new_cont">{{data.subs}}</div>
						</div>
					</div>
					<div class="yema">
						<div class="qian" @tap='prev()' v-if="show_prev">上一页</div>
						<div class="qian act" v-else="show_prev">上一页</div>
						<div class="next" @tap='next()' v-if="show_next">下一页</div>
						<div class="next act" v-else="show_next">下一页</div>
					</div>
				</section>
				<dfFooter></dfFooter>
			</div>
		</view>
	</view>
</template>
<script>
	export default {
		components: {},
		data() {
			return {
				search_str: '123',
				dataList: [],
				pageIndex: 0,
				show_prev: false,
				show_next: true,
				loading: true,
				// 当前菜单index
				tabIndex: 0,
				// 当前菜单id
				tabId: "all",
				order: "time",
			}
		},
		onLoad(event) {			
			this.search_str = this.$Route.query.search;
			console.log(this.search_str)
			this.getList(this.search_str);
			this.$functions.setPageData(this.tabId);
		},
		methods: {
			search(res) {
				var str = res.detail.value;
				uni.showLoading({
					title: "搜索中..."
				})
				this.reload = true;
				this.pageIndex = 0;
				this.show_prev = false;
				this.show_next = true;
				this.getList(str)
			},
			prev() {
				this.pageIndex--;
				if (this.pageIndex <= 0) {
					this.show_prev = false;
				}
				this.reload = true;
				this.show_next = true;
				this.getList(this.search_str);
			},
			next() {
				this.pageIndex++;
				this.reload = true;
				this.show_prev = true;
				this.getList(this.search_str);
			},
			// 获取数据列表
			getList(str = "") {
				// 获取某个菜单下的数据				
				let _this = this;
				this.search_str = str;
				var para = {
					pageSize: 8,
					pageIndex: this.pageIndex,
					typeId: this.tabId,
					order: this.order,
					search: str
				};
				this.$request.api_request('', para).then(function(data) {
					data = data.result;
					let list = _this.setData(data);
					// console.log(list)

					//首次加载直接赋值，之后追加
					_this.dataList = _this.reload ? list : _this.dataList.concat(list);
					_this.reload = false;
					// 取消刷新图标
					uni.stopPullDownRefresh();
					uni.hideLoading()

					_this.loading = false

					console.log(list.length, para.pageSize)
					if (list.length < para.pageSize) {
						_this.show_next = false;
					}
				})
			},
			setData: function(items) {
				return this.$functions.setData(items, true);
			},
			goDetail: function(e) {
				this.$functions.goDetail(e, this)
			},
		},
		watch: {}
	}
</script>

<style lang="scss">
	@import '@/static/css/online/index.scss';
</style>
